package com.cat.model.web.action.api;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.cat.model.biz.service.api.BasOrderService;
import com.cat.model.common.model.common.UserTokenVO;
import com.cat.model.common.util.ErrorCode;
import com.cat.model.dao.mapper.UserInfoMapper;
import com.cat.model.web.action.base.BaseAction;

public class WXOpenPayAction  extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5811123220652568096L;

	@Autowired
	private UserInfoMapper userInfoMapper;
	@Autowired
	private BasOrderService basOrderService;
	
	private String token;
	private String orderNumber;
	/**
	 * 根据订单id获取支付信息
	 * */
	public void getPayInfo(){
		if(StringUtils.isEmpty(token)||org.apache.commons.lang3.StringUtils.isBlank(orderNumber)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		print(basOrderService.getWXPayInfo(userToken.getUserId(),orderNumber));
	}
	
	
	
	/**
	 * 获取微信预下单信息
	 * */
	public void getPrePayInfo(){
		if(StringUtils.isEmpty(token)||org.apache.commons.lang3.StringUtils.isBlank(orderNumber)){
			print(ErrorCode.PARAM_ERROR.response());
			return;
		}
		//token过期
		UserTokenVO userToken = userInfoMapper.getUserTokenByToken(token);
		if(null == userToken || userToken.getTokenExpire() < new Date().getTime()){
			print(ErrorCode.TOKEN_EXPIRE.response());
			return;
		}
		print(basOrderService.getPrePayInfo(userToken.getUserId(),orderNumber));
	}
	
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public String getOrderNumber() {
		return orderNumber;
	}
	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}
	
}
